<?php

namespace co2\dev\v0_0_0;

class File

{
	protected
		$name,
		$path
		;
		
	public function
	__construct
	(
		$name
	)
	
	{
		$this->name=$name;
	}
	
	public function
	create
	(
	)
	
	{
		if(!touch($this->name))
		throw new Exception('could not create file '.$this->name);
		
		return $this;
	}
	
	public function
	get
	(
		
	)
	{
		return trim(file_get_contents($this->name));
	}
	
	public function
	put
	(
		$contents
	)
	{
		if(!is_int(file_put_contents($this->name,$contents,FILE_USE_INCLUDE_PATH | LOCK_EX)))
		throw new Exception('could not put contents to file');
		
		return $this;
	}
	
	public function
	append
	(
		$string
	)
	{
		if(!is_int(file_put_contents($this->name,$string,FILE_APPEND)))
		throw new Exception('could not append string to file');
		
		return $this;
	}
	
	public function
	own
	(
		$user,
		$group=null,
		$recursive=false
	)
	
	{
		new bash\chown($this->name,$user,$group,$recursive);
		
		return $this;
	}
	
	public function
	__toString
	(
	)
	
	{
		return $this->name;
	}
}
